package code.ws_common_scene.eft
{
	import code.ws_common_scene.texturedata.TexturePlayData;
	
	import flash.display.BitmapData;
	
	import starling.display.Sprite;
	import starling.textures.Texture;
	import starling.utils.Color;

	/**
	 * 特效基类 
	 * @author qiangchen
	 * 
	 */	
	public class Effects extends Sprite
	{
		/** 样式 */
		private var _style:String = null;
		/** 索引值id */
		private var _eftId:String = null;
		/** 刷新器 */
		public var _viewClip:EViewClip = null;
		/** 暂停 */
		private var _pause:Boolean = true;
		/** 开关 */
		private var _flag:Boolean = true;
		
		
		/**
		 * 构造函数 
		 * @param style
		 * @param eftId
		 */		
		public function Effects( style:String, eftId:String )
		{
			this.touchable = false;
			_style = style;
			_eftId = eftId;
			
			_viewClip = new EViewClip();
			_viewClip.ini( _style );
			addChild( _viewClip );
		}
		
		
		/**
		 * 刷新 
		 * 
		 */		
		public function refresh():void
		{
			if( !_flag ) return;
			if( !_pause ) return;
			
			if( _viewClip )
			{
				_viewClip.refresh();	
			}
		}
		
		
		/**
		 * 是否开启触摸感应 
		 * @param bol
		 * 
		 */		
		public function isTouchable( bol:Boolean ):void
		{
			this.touchable = bol;
		}
		
		
		/**
		 * 开关设置 
		 * @param bol 如果为false，那么播放头放置第0帧，并且取消当前正在加载的样式（如果有加载器在运行）。
		 * 
		 */		
		public function set flag( bol:Boolean ):void
		{
			_flag = bol;
			if( !bol ) 
			{
				_viewClip.cancelLoa();
				_viewClip._crtFrame = 0;
				_viewClip._fr = 0;
				_viewClip.texture = Texture.fromBitmapData( new BitmapData(1,1,false,Color.BLACK), false );
				_viewClip.readjustSize();
			}
		}
		public function get flag():Boolean{return _flag};
		
		/**
		 * 设置特效刷新器开关 
		 * @param bol
		 * 
		 */		
		public function set pause( bol:Boolean ):void{_pause = bol};
		public function get pause():Boolean{return _pause};
		
		/**
		 * 获取播放数据 
		 * @return 
		 * 
		 */		
		public function get playData():TexturePlayData { return _viewClip.playData };
		
		/**
		 * 获取样式 
		 * @return 
		 * 
		 */		
		public function get style():String { return _style };
		
		/**
		 * 索引值 
		 * @return 
		 * 
		 */		
		public function get eftId():String{ return _eftId };
		
		
		/**
		 * 释放 
		 * 
		 */		
		override public function dispose():void
		{
			if( _viewClip )
			{
				_viewClip.dispose();
			}
			_eftId = null;
			_style = null;
			super.dispose();
		}
	}
}